<?php
use Webmozart\PathUtil\Path;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\Support\Carbon;


if (! function_exists('loadLibrary')) {
    /**
     * Loads and instantiates helpers.
     * Designed to be called from application controllers.
     *
     * @param   string  $library Library name
     * @param   string  $class_name An optional object name to assign to
     * @param   array   $params Optional parameters to pass to the library class constructor
     * @return  object|array
     */
    function loadLibrary($library, $class_name = null, $params = []){
        $name = Path::getFilename($library);
        $path = Path::join(__DIR__, "Libraries", $name . ".php");
        if (!file_exists($path)) {
            throw new FileNotFoundException("{$path} file not found!");
        }
        include_once($path);
        if (is_string($class_name)) {
            return isset($params)
            ? new $class_name(...$params)
            : new $class_name();
        }
    }
}